/**
* 自己定义的一个显示调试信息的东西
*注意如果大规模打出调试信息就会造成播放器迟钝，最明显的就是歌曲淡出的时候一顿一顿的
*_root.tf_tracer
*/
package kgame5.kutil {
import flash.events.*;
import flash.net.*;
import flash.utils.ByteArray;

public class T{

//	private static const MAXLINENUM:int=130;//超过100行就自己清空
//	private static var linenum:int=1;
	
	public static var lc_sender:LocalConnection;
	
	public static function p(...args):void{
		
		trace (args);
		
		
		if(OK){//这个是判断，如果发送失败（就是本地没有调试器）就不要再发了,节约资源 
			var s:String="";
			for(var i:int=0;i<args.length;i++){
				s+=args[i]+" ";
			}
				
			//使用localConnection来连接
			if(lc_sender==null){
				lc_sender=new LocalConnection();
				lc_sender.addEventListener(StatusEvent.STATUS, onStatus);
			}
			
			lc_sender.send("_musicmaid8","lcHandler",s);
		}
	}
	private static var OK:Boolean=true;
	private static  function onStatus(e:StatusEvent):void {
        switch (e.level) {
            case "status":
                 //trace("LocalConnection.send() succeeded");
                 break;
            case "error":
               	OK=false;//发生了错误，不能再发了
                 //trace("LocalConnection.send() failed");
                 break;
        }
    }
	
	//严重注意，用完了要把positon设置成原来的数值
	public static function traceByteArray(ba:ByteArray):void{
		var prePosi:int=ba.position;
		var ss:String="";
		ba.position=0;
		for(var i:int=0;i<ba.length;i++){
			ss+=ba.readUnsignedByte()+",";
		}
		T.p(ss);
		ba.position=prePosi;
	}
	///////////textArea打出调试信息//////////////////////
	///////////////////////////////
	
	////////////////////////////////
	////////////////////////////////
	/*
	private static var b_scroll:Boolean=true;
	
	
	//比较详细的打出调试信息
	public static function DeepTrace(o){
		for(var i in o){
			p(i+":"+o[i]);
		}
	}
	////////////////
	//
	public static function TraceStationInfo(si:Object){
		
		p("~SI:"+si.iStationID+" "+si.sStationName+" sd:"+si.iSearchDegree+" "+si.iStationType+" "+si.iStationSubType+" "+si.aPlayList.length);
		
		var s:String="aSex ";
		for(var i in si.a_iSex){
			s+="  "+i+" :"+si.a_iSex[i];
		}
		p(s);
		
		s="aLan ";
		for(var i in si.a_iLan){
			s+="  "+i+":"+si.a_iLan[i];
		}
		p(s);
		
		s="aMixed ";
		for(var i in si.a_iMixed){
			s+="  "+i+":"+si.a_iMixed[i];
		}
		p(s);
		
	}
	//把音乐卡片的详细信息打印成字符串
	public static function TraceCardInfo(ci:Object){
		
		
		var s:String=ci.sAlbumUrl;
		p("CIF:"
			//+" sAlbumUrl:"+s.substr(-7,7)
			+"songName:"+ci.sSongName+" songID:"+ci.iSongID
			+"singerName:"+ci.sSingerName+" singerID:"+ci.iSingerID
			//+" sFileUrl:"+p_info.sFileUrl
			//+" sLrcUrl:"+p_info.sLrcUrl
			);
		
		//+"iAlbumID:"+p_info.iAlbumID+newline
		//+"sAlbumName:"+p_info.sAlbumName+newline
		//+"iSingerID:"+p_info.iSingerID+newline
	
		//+"sFileUrl:"+p_info.sFileUrl+newline
		//+"sAddedDate:"+p_info.sAddedDate
		
	}
	public static function TracePlayList(aPlayList:Array){
		
		p("PLAYLIST:"+aPlayList.length);
		for(var i=0;i<aPlayList.length;i++){
			T.p(i+":");
			TraceCardInfo(aPlayList[i]);
		}
	}
	public static function TraceContent(mc:MovieClip){
		p("content of:"+mc);
		for(var i in mc){
			p(i+" "+mc[i]);
		}
	}
	
	//*/
	//显示一个2维数组
	public static function TraceArray2(a2:Array):void{
		p("");
		for(var r:int=0,RC:int=a2.length;r<RC;r++){
			var t:String=r+": ";
			for(var c:int=0,CC:int=a2[r].length;c<CC;c++){
				t+=" "+a2[r][c];
			}
			p(t);
		}
	}
	
	//
	public static function deepTrace( obj : *, level : int = 0 ) : void{
        var tabs : String = "";
        for ( var i : int = 0 ; i < level ; i++, tabs += "\t" ){}
        
        for ( var prop : String in obj ){
            trace( tabs + "[" + prop + "] -> " + obj[ prop ] );
            deepTrace( obj[ prop ], level + 1 );
        }
    }

} //end of class
}